package com.itheima.inetaddress;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class Demo05 {
    public static void main(String[] args) throws IOException {
        //创建码头
        DatagramSocket ds = new DatagramSocket(1000);
        while (true) {
            //创建小箱子
            byte[] bytes = new byte[1024];
            //创建大箱子
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length);

            //装数据
            ds.receive(dp);
            //取数据
            byte[] data = dp.getData();
            int length = dp.getLength();

            //打印数据
            System.out.println(new String(data,0,length));
        }

        //释放资源
        //ds.close();

    }
}
